﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

namespace Skynet.DynamicSite.DynamicData.FieldTemplates
{
    public partial class Time_EditField : System.Web.DynamicData.FieldTemplateUserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        { 
            StringBuilder sb = new StringBuilder();
            sb.Append("<script>");
            sb.Append("$('#" + this.txtDate.ClientID + "').datepicker();");              
            sb.Append("</script>");
            this.Page.ClientScript.RegisterStartupScript(GetType(), this.Column.Name +"_time_edit" , sb.ToString());            
        }


        protected override void ExtractValues(System.Collections.Specialized.IOrderedDictionary dictionary)
        {            
            dictionary[Column.Name] = DateTime.Parse(this.txtDate.Text + " " + this.txtTime.Text);
        }

        protected void TimeValidation_ServerValidate(object source, ServerValidateEventArgs args)
        {
            //if(  this.Column.IsCustomProperty) 

            DateTime output ;
            args.IsValid = DateTime.TryParse(this.txtDate.Text + " " + this.txtTime.Text, out output);            
        }
    }
}